package com.share.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.device.domain.Cabinet;
import com.share.device.domain.Tactics;
import com.share.device.domain.vo.TacticsVo;
import com.share.device.mapper.TacticsMapper;
import com.share.device.service.CabinetService;
import com.share.device.service.TacticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TacticsServiceImpl extends ServiceImpl<TacticsMapper, Tactics> implements TacticsService {
    @Autowired
    private TacticsMapper tacticsMapper;
    @Autowired
    private CabinetService cabinetService;
    @Override
    public List<Tactics> selectTacticsList(Tactics tactics) {
        return tacticsMapper.selectTacticsList(tactics);
    }

    @Override
    public TacticsVo getTactics(Long id) {
        //根据id获取tactics
        Tactics tactics = this.getById(id);
        TacticsVo vo = new TacticsVo();
        //根据策略id获取柜机集合
        List<Cabinet> list = cabinetService.list(new LambdaQueryWrapper<Cabinet>().eq(Cabinet::getTacticsId, id));
        vo.setTacticsName(tactics.getTacticsName());
        vo.setTacticsScheme(tactics.getTacticsScheme());
        vo.setCabinetList(list);
        return vo;
    }
}
